import VueRouter from 'vue-router'

import Login from './components/Login.vue'
import Register from './components/Register.vue'
import MainContent from './components/MainContent.vue'
import InfoContent from './components/subcomponents/InfoContent.vue'
import RecoverPassword from './components/subcomponents/RecoverPassword.vue'
import GoodsList from './components/subcomponents/GoodsList.vue'
import OrderList from './components/subcomponents/OrderList.vue'
import GoodsInfo from './components/subcomponents/GoodsInfo.vue'
import NotFoundComponent from './components/NotFoundComponent.vue'
import Firstpage from './components/subcomponents/firstpage.vue'
import Addgoods from './components/subcomponents/addgoods.vue'

var router = new VueRouter({
	// mode: 'history', 
	// base: '/',
	routes:[
		{	
			// 重定向
			path:'/',
			redirect:'/login'
		},
		{ 
			meta: { title: '页面不存在' },
			path: '*', 
			component: NotFoundComponent 
		},
		{	
			// 登录
			meta: { title: '登录' },
			path:'/login',
			name:'login',
			component:Login
		},
		{
			// 注册
			meta: { title: '注册' },
			path:'/register',
			name:'register',
			component:Register

		},
		{
			// 主页面
			meta: { 
				title: '首页',
				requireAuth:true 
			},
			path:'/main',
			name: 'main',
			component:MainContent,
			children:[
				{
					path:'/',redirect:'firstpage'
				},
				{
					// 首页
					meta: { 
						title: '首页',
						requireAuth:true  
					},
                    path: 'firstpage',
                    name: 'firstpage',
                    component: Firstpage
				},
				{ 
					// 账号信息
					meta: { 
						title: '账号信息' ,
						requireAuth:true 
					},
                    path: 'userinfo',
                    name: 'userinfo',
                    component: InfoContent
                }, { 
					// 修改密码
					meta: { 
						title: '修改密码' ,
						requireAuth:true 
					},
                    path: 'recover',
                    name: 'recover',
                    component: RecoverPassword
                }, { 
					// 商品列表
					meta: {
						title: '商品列表',
						requireAuth:true  
						},
                    path: 'goodslist',
                    name: 'goodslist',
                    component: GoodsList
                }, { 
					// 订单列表
					meta: { 
						title: '订单列表' ,
						requireAuth:true 
					},
                    path: 'orderlist',
                    name: 'orderlist',
                    component: OrderList
                },{ 
					// 商品详情
					isHidden: true,
					meta: { 
						title: '商品详情' ,
						requireAuth:true 
					},
                    path: 'goodsinfo',
                    name: 'goodsinfo',
                    component: GoodsInfo
				},{ 
					// 新增商品
					isHidden: true,
					meta: {
						title: '新增商品' ,
						requireAuth:true 
					},
                    path: 'addgoods',
                    name: 'addgoods',
                    component: Addgoods
                }
			]
		}
	],
	// linkActiveClass:'mui-active'
})

router.beforeEach((to, from, next) => {
	if (to.meta.title) {
	  document.title = to.meta.title;
	}

	// if(to.meta.requireAuth&&!sessionStorage.getItem('accessToken')){
	// 	next({path:'/login'})
	// }else{
	// 	next();
	// }
	next();
  });

export default router